package main

import (
	"bubble/config"
	"bubble/controller"
	"bubble/routers"
	"fmt"
	"log"
	"net/http"

	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"
)

func main() {
	gin.SetMode(config.AppModel)

	r := gin.Default()

	// 静态资源
	r.Static("/static", "static")
	// html 模板文件源
	r.LoadHTMLGlob("templates/*")

	r.GET("/", controller.GetIndex)

	v1 := r.Group("v1")
	{
		routers.InitTodo(v1)
	}

	s := http.Server{
		Addr:              fmt.Sprintf(":%s", config.HttpPort),
		Handler:           r,
		ReadHeaderTimeout: config.HttpReadOutTime,
		WriteTimeout:      config.HttpWriteOutTime,
	}

	if err := s.ListenAndServe(); err != nil {
		log.Fatalf("启动服务失败：%s/n", err)
	}
}
